<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>消防进军训测试题</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui">
    <meta content="telephone=no" name="format-detection" />
    <meta content="email=no" name="format-detection" />
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <link rel="stylesheet" href="{{asset('js/jquery-weui/dist/lib/weui.min.css')}}">
    <link rel="stylesheet" href="{{asset('js/jquery-weui/dist/css/jquery-weui.min.css')}}">
    <link rel="stylesheet" href="{{asset('dist/app.min.css').'?v='.config('answer.version')}}">

    <script src="{{asset('js/jquery-weui/dist/lib/jquery-2.1.4.js')}}"></script>
    <script src="{{asset('js/jquery-weui/dist/js/jquery-weui.min.js')}}"></script>
    <script src="{{asset('js/jquery-weui/dist/lib/fastclick.js')}}"></script>

</head>
<body class="first-page">

<form action="" novalidate method="post" class="login-form">
    <div class="weui-cells">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="username" name="name" data-reg="^[\u4E00-\u9FA5A-Za-z0-9]+$" type="text" placeholder="请输入姓名" data-msg-reg="姓名输入有误" required>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="phone" name="phone" data-reg="^1[34578]\d{9}$" type="text" placeholder="请输入手机号" data-msg-reg="手机号输入有误" required>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="city" name="city" type="text" placeholder="请选择所在城市" required>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" id="school" name="school" data-reg="^[\u4E00-\u9FA5A-Za-z0-9]+$" type="text" placeholder="请输入所在学校" data-msg-reg="学校输入有误" required>
            </div>
        </div>
    </div>
    <a href="javascript:;" id="examBtn" class="weui-btn weui-btn_warn" style="margin-bottom: 10px;">开始答题</a>
    {{--<div class="weui-footer">
        <a href="{{route('exam')}}" class="weui-footer__text">跳过，直接进入答题</a>
    </div>--}}


</form>
<script>

    $(document).ready(function(){
        //FastClick
        FastClick.attach(document.body);

        //初始化页面
        Page.initPage();
    });
    var Page = {
        flag:0,
        /**
         * 初始化页面
         */
        initPage:function(){
            var self = this;
            /*$(document.body).on("touchmove", function (e) {
                //禁止触摸事件
                e.preventDefault();
            });*/
            self.initEvent();
        },
        /**
         * 初始化事件
         */
        initEvent:function(){
            var self = this;

            //地区选择
            self.selectBox();

            //开始答题按钮
            $("#examBtn").click(function() {
                var form=$('.login-form');
                var inputs=form.find('input');
                if(!self.regInput(inputs)) {
                    return false;
                }else if(!self.flag){
                    self.setUserInfo();
                }
            });

        },

        /**
         * 提交用户信息
         */
        setUserInfo:function(){
            var self = this;
            self.flag=1;

            //ajax提交用户信息
            var username    = $('#username').val();
            var phone       = $('#phone').val();
            var city    = $('#city').val();
            var school      = $('#school').val();
            var info={
                "username":username,
                "phone":phone,
                "city":city,
                "school":school
            };
            window.localStorage.setItem('exam_user_info',JSON.stringify(info));
            location.href='{{route('exam')}}';
        },
        //函数：检查表单符合正则(DOM)
        regInput:function (dom){
            var v=!0;
            var error='';
            dom.each(function(){
                var that=$(this);
                if(that.prop('required')&&that.val()===''){
                    error=!error?that.attr('data-msg-required')||that.attr('placeholder')||'有必填项未填写':error;
                    v=!1;
                }else if(that.attr("data-reg")&&(new RegExp(that.attr("data-reg"))).exec(that.val())===null){
                    v=!1;
                    !error&&(error=that.attr('data-msg-reg'));
                }
            });
            v||$.toptip(error,'warning');
            return v;
        },
        selectBox:function () {
            $("#city").select({
                title: "所在城市",
                items: ('郑州市，开封市，洛阳市，平顶山市，安阳市，鹤壁市，新乡市，焦作市，濮阳市，许昌市，漯河市，三门峡市，南阳市，商丘市，信阳市，周口市，驻马店市，济源市，郑州航空港区').split('，')
            });
        }
    }


</script>
</body>
</html>